package hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : HashMapTest
 * @Author : 54061
 * @Date: 2022/2/10 9:57
 */
public class HashMapTest {
    public static void main(String[] args) {

        HashMap<Character,Integer> hm = new HashMap<>();
        //键盘录入
        Scanner sc = new Scanner(System.in);
        //提示
        System.out.println("请您输入一句话");

        String line = sc.nextLine();

        //遍历字符串
        for (int i = 0 ; i<line.length();i++){
            //取字符
            char ch = line.charAt(i);
            //把字符往集合中添加
            if (hm.containsKey(ch)){
                //包含key
                Integer count = hm.get(ch);//原来的次数
                hm.put(ch,count+1);
            }else {
                //不包含
                hm.put(ch,1);//第一次出现
            }
        }
        //遍历集合去除集合中的字符次数
        Set<Map.Entry<Character,Integer>> entries = hm.entrySet();
        for (Map.Entry<Character,Integer>entry : entries){
            Character Key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println( Key  + value);
        }
    }
}
